<template>
  <l-upload
    :showFileList="false"
    :btnText="text"
    :uploadCallback="uploadCallback"
    :accept="`.${fileType}`"
    :limit="1000"
    btnType="defualt"
    :isSecretLevel="false"
    @success="handleSuccess"
    @start="handleStart"
    @error="handleError"
  />
</template>

<script>
export default {
  name: "l-file-import",
  props: {
    classname: String,
    text: {
      type: String,
      default: "导入",
    },
    fileType: String,
  },
  data() {
    return {
      handleLoading:null
    };
  },
  mounted() {},
  computed: {},
  methods: {
    handleStart() {
      this.handleLoading = this.$loading({
        lock: true,
        text: "File 导入中",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)",
      });
    },
    handleSuccess() {
      this.handleLoading.close()
      this.$emit("success");
    },
    handleError(){
      this.handleLoading.close()
    },
    uploadCallback(data) {
      const api = window.$api.system.annexesFile;
      return api.uploadTemp(this.classname, data);
    },
  },
};
</script>
